******************************************************************
*** Replication Do-file - Main Text
******************************************************************

clear

use data47-125.dta

*********************
*** Data Cleaning ***
*********************

*** There are 78 weeks in total with the new grading system starting from week 47. 

*** Data from a particular week is dropped if:
// (1) If one of the consetants is disqualified (dummy variable "disqualified")
// (2) If one of the contestans could not finish the menu (dummy variable "unfinished_menu")
// (3) If the groom instead of the bride participated (dummy variable "groom")
// (4) IF winners from previous episodes particpated again (dummy variable "previous_winner)

drop if disqualified==1
drop if unfinished_menu==1
drop if groom==1
drop if previous_winner==1

*** Renumber weeks
egen week_new=group(week) 
replace week=week_new
drop week_new

save data_analysis.dta, replace


***************************************
*** Table 1 - Descriptive Statistics **
***************************************

tabstat points if !missing(points), stat(mean sd min max)
tabstat cookfirst cook_second cook_third cook_fourth cook_fifth already_cooked if !missing(points), stat(mean sd min max)
tabstat host if !missing(points), stat(mean sd min max)

tabstat host if cookfirst==1 & i_cook==1,stat(mean sd min max)
tabstat host if cook_second==1 & i_cook==1,stat(mean sd min max)
tabstat host if cook_third==1 & i_cook==1,stat(mean sd min max)
tabstat host if cook_fourth==1 & i_cook==1,stat(mean sd min max)
tabstat host if cook_fifth==1 & i_cook==1,stat(mean sd min max)

tabstat total if cookfirst==1 & i_cook==1,stat(mean sd min max)
tabstat total if cook_second==1 & i_cook==1,stat(mean sd min max)
tabstat total if cook_third==1 & i_cook==1,stat(mean sd min max)
tabstat total if cook_fourth==1 & i_cook==1,stat(mean sd min max)
tabstat total if cook_fifth==1 & i_cook==1,stat(mean sd min max)

tabstat total, stat(mean sd min max)
tabstat overall, stat(mean sd min max)

***************************************************
*** Table 2  and Figure 1 Distribution of Points **
***************************************************
set scheme s1mono
graph bar (count), over(points)
tab points

bysort cook: tab points


************************************************
*** Table 3 - Evaluator Fixed Effects Estimation
************************************************

** Create a unique ID for every contestant-week combination 
egen unique_evaluator_id = group(week evaluator)

xtset unique_evaluator_id

*** Naive Model - Column (1) without "already cooked"

xtreg points cook_second cook_third cook_fourth cook_fifth host , fe cluster(week)

*** Full Model - Column (2) with "already cooked"

xtreg points cook_second cook_third cook_fourth cook_fifth already_cooked host , fe cluster(week)

*** Excluding Host - Column (3)

xtreg points cook_second cook_third cook_fourth cook_fifth already_cooked , fe cluster(week)


*******************************************************
*** Table 5 and Figure 2 - Model with Interaction Terms
*******************************************************

*** Create a "cook order" variable from dummies
gen cook_order = 1  
replace cook_order = 2 if cook_second == 1
replace cook_order = 3 if cook_third == 1
replace cook_order = 4 if cook_fourth == 1
replace cook_order = 5 if cook_fifth == 1

*** Regression with interaction terms
reg points i.cook_order##i.already_cooked host i.week, cluster(week)

*** Calculate the predictions
margins cook_order, over(already_cooked)

*** Figure 2 - Margins Plot
marginsplot, x(cook_order) noci ///
    title("Decomposition of Order Effects") ///
    ytitle("Predicted Score") ///
    legend(label(1 "Evaluator Has Not Cooked") label(2 "Evaluator Has Already Cooked")) 

*********************************************
*** Table 6 - FE vs. Mixed Models  **********
*********************************************

xtset unique_evaluator_id

*** Main Model (FE) - Column (1)
xtreg points i.cook_order i.already_cooked host, fe cluster(week)


*** Hierarchical (Mixed) Model - Column (2)
mixed points i.cook_order i.already_cooked host || week: || unique_evaluator_id:, std


*** Random Effects Model - Column (3)
xtreg points i.cook_order i.already_cooked host i.week, re cluster(week)


********************************************
*** Table 7 - Probability of Winning *******
********************************************

*** Create a tag that equals 1 for exactly one row per contestant per week
egen cook_tag = tag(week cook)

bysort week: egen maxpoints=max(overall)
gen winner=1 if overall==maxpoints
replace winner=0 if winner==.

*** Linear Probability Model - Column (1)
reg winner cook_second cook_third cook_fourth cook_fifth host i.week if cook_tag==1, cluster(week)

*** Logit Regression - Column (2)	
logit winner cook_second cook_third cook_fourth cook_fifth host i.week if cook_tag==1, cluster(week)	
margins, dydx(*)

*** Probit Regression - Column (3)	
probit winner cook_second cook_third cook_fourth cook_fifth host i.week if cook_tag==1, cluster(week)		
margins, dydx(*)


**************************************************
*** Table (8) - Evidence on Host Scoring Behaviour
**************************************************

preserve

*** Collapse to get 1 row per cook
*** peer_avg: calculated from the 'points' column
*** host_score: takes the 'host' column (which is constant for that cook)
*** cook_order variables: keep the max (since 1 is present in the group)
collapse (mean) peer_avg=points (first) host_score=host ///
         (max) cookfirst cook_second cook_third cook_fourth, ///
         by(week cook)
		 
*** Regress Host Score on Peer Average - Panel (A)
reg host_score peer_avg i.week, cluster(week)


*** Standard Deviations of Scores - Panel (B)
tabstat peer_avg, stat(sd mean min max)
tabstat host_score, stat(sd mean min max)	

restore

**************************************************
*** Table 9 - Reciprocity and Strategic Robustness
**************************************************

*** Prepare the lookup data
preserve

keep week cook evaluator points
rename points score_received

*** swap ID's: We want to match this to the "Reverse" pair.
*** If the original row is "Cook A, Evaluator B", we want to save it as
*** a lookup for when "Cook B" is being evaluated by "Evaluator A".
rename cook temp_eval
rename evaluator temp_cook

rename temp_eval evaluator
rename temp_cook cook

save "reciprocity_lookup.dta", replace

restore


*** We pull that information back into the main dataset
merge 1:1 week cook evaluator using "reciprocity_lookup.dta", keepusing(score_received)

* Clean up
drop if _merge == 2  
drop _merge

replace score_received = . if already_cooked == 0

*** Restricted Sample - Reciprocity Only - Column (1)
reg points score_received host i.week, cluster(week)


*** Full Sample with mean imputation - Column (2)
gen score_received_imputed = score_received
replace score_received_imputed = 4.99 if already_cooked == 0

xtset unique_evaluator_id

xtreg points cook_second cook_third cook_fourth cook_fifth ///
      already_cooked score_received_imputed host, fe cluster(week)


*** Compliant Evaluators only - Column (3) 

preserve

gen non_compliant_score = (points < 3 | points > 6) & !missing(points)

*** Check if the evaluator EVER broke the rule during the week
bysort unique_evaluator_id: egen evaluator_broke_rule = max(non_compliant_score)

keep if evaluator_broke_rule == 0

drop if missing(points)

xtreg points cook_second cook_third cook_fourth cook_fifth ///
      i.already_cooked score_received_imputed host, fe cluster(week)
      
restore











